package jrmob.yonyou.com.commonlib.baseadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * BaseAdapter 基类
 * Created by zhangguang on 16/10/22.
 */

public abstract  class BaseAdapterEx_lib  extends BaseAdapter {

    protected Context context;
    protected LayoutInflater inflater;
    protected List itemList = new ArrayList();

    public BaseAdapterEx_lib(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }


    public BaseAdapterEx_lib(Context context ,List itemList) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.itemList = itemList;
    }

    /**
     * 判断数据是否为空
     *
     * @return 为空返回true，不为空返回false
     */
    public boolean isEmpty() {
        return itemList.isEmpty();
    }

    /**
     * 在原有的数据上添加新数据
     *
     * @param itemList
     */
    public void addItems(List itemList) {
        this.itemList.addAll(itemList);
        notifyDataSetChanged();
    }

    /**
     * 设置为新的数据，旧数据会被清空
     *
     * @param itemList
     */
    public void setItems(List itemList) {
        this.itemList.clear();
        this.itemList = itemList;
        notifyDataSetChanged();
    }

    /**
     * 清空数据
     */
    public void clearItems() {
        itemList.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Object getItem(int i) {
        return itemList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public abstract View getView(int i, View view, ViewGroup viewGroup);
}